package cn.edu.sasu.controller;

import cn.edu.sasu.common.annotation.RoleNum;
import cn.edu.sasu.common.base.LayuiRespResult;
import cn.edu.sasu.common.base.RespResult;
import cn.edu.sasu.common.constants.Role;
import cn.edu.sasu.domain.dto.SysRoleSaveDTO;
import cn.edu.sasu.domain.vo.SysRoleVO;
import cn.edu.sasu.domain.vo.SysUserInfoVO;
import cn.edu.sasu.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/sys_role")
public class SysRoleController {

     @Autowired
     private SysRoleService sysRoleService;

     // 查询系统用户信息
     @RoleNum(Role.COMMON)
     @GetMapping("/findSysRoleAll")
     public LayuiRespResult findSysRoleAll(Integer page,Integer limit){
          return sysRoleService.findSysRoleAll(page,limit);
     }

     // 删除
     @RoleNum(Role.ADMIN)
     @PostMapping("/del")
     public RespResult del(Integer roleId){
          return sysRoleService.delSysRoleByRoleId(roleId);
     }

     // 批量删除
     @RoleNum(Role.ADMIN)
     @PostMapping("/batchdel")
     public RespResult batchdel(Integer[] roleIds){
          return sysRoleService.batchdel(roleIds);
     }

     // 搜索
     @RoleNum(Role.COMMON)
     @GetMapping("/search")
     public LayuiRespResult search(Integer page,Integer limit,String username){
          return sysRoleService.search(page,limit,username);
     }

     // 保存
     @RoleNum(Role.COMMON)
     @PostMapping("/save")
     public RespResult save(@RequestBody @Validated SysRoleSaveDTO sysRoleSaveDTO){
          return sysRoleService.save(sysRoleSaveDTO);
     }

     @RoleNum(Role.ADMIN)
     @PostMapping("/update")
     public RespResult updateInfo(@RequestBody SysRoleVO roleVO){
          return sysRoleService.updateInfo(roleVO);
     }
}
